package com.micro.frog.rbac.controller;

import com.micro.frog.rbac.dto.UserDetail;
import com.micro.frog.rbac.util.CookieUtil;
import com.micro.frog.rbac.util.SubjectUtil;
import com.micro.frog.rbac.utils.CacheUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author :  ljh
 * @date : 2018/4/9
 **/
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    /**
     * 后台系统首页
     */
    @RequestMapping("/main")
    public String main(HttpServletRequest request, Model model) {
        UserDetail user = SubjectUtil.getUser(request);
        model.addAttribute("user", user);
        return "main";
    }

    /**
     * 后台系统欢迎页
     */
    @RequestMapping("/index")
    public String index() {
        return "index";
    }

    /**
     * 后台系统登录页
     */
    @RequestMapping("/login.htm")
    public String login() {
        return "login";
    }

    @RequestMapping(value = "/logout")
    public String logout(HttpServletRequest request) {
        String result = null;
        try {
            String token = CookieUtil.getToken(request);
            CacheUtil.delete(token);
            result = "redirect:/admin/login.htm";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 后台菜单管理页
     */
    @RequestMapping("/menuManage")
    public String menu() {
        return "rbac/menu/menuList";
    }

    /**
     * 后台用户管理页
     */
    @RequestMapping("/userManage")
    public String userManager() {
        return "rbac/user/userList";
    }

    /**
     * 后台字典管理页
     */
    @RequestMapping("/dictManage")
    public String dictManage() {
        return "rbac/dict/dictList";
    }

    /**
     * 后台权限管理页
     */
    @RequestMapping("/rbacManage")
    public String rbacManage() {
        return "rbac/role/roleList";
    }

    /**
     * 后台任务管理页
     */
    @RequestMapping("/taskManage")
    public String rbacTask() {
        return "rbac/task/taskList";
    }
}
